package com.sky.controller.admin;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "菜品相关接口")
@Slf4j
@RequestMapping("/admin/dish")
@RestController

public class DishController {
    @Autowired
    private DishService dishService;
    @ApiOperation("新增菜品")
    @PostMapping
    public Result save(@RequestBody DishDTO dto) {
        log.info("新增菜品：{}", dto);

        dishService.saveWithFlavor(dto);
        return Result.success();
    }
    @ApiOperation("菜品分页条件查询")
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dto ){
        log.info("菜品分页条件查询：{}",dto);
        PageResult pageResult= dishService.pageQuery(dto);
        return Result.success(pageResult);
    }
    @ApiOperation("删除菜品")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除菜品:{}",ids);
        dishService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @ApiOperation("根据Id查询菜品")
    @GetMapping("/{id}")
    public Result<DishVO> getById(@PathVariable Long id){
        log.info("根据id查询菜品",id );
        DishVO result=dishService.getById(id);
        return Result.success(result);
    }

    /**
     * 修改菜品
     * @param dto
     * @return
     */
    @ApiOperation("根据id修改菜品")
    @PutMapping()
    public Result update(@RequestBody DishDTO dto){
        log.info("根据id修改菜品:{}",dto);
        dishService.updateWithFlavor(dto);
        return Result.success();
    }



//    @ApiOperation("修改菜品")
//    @PutMapping
//    public  Result<DishVO>
}
